package pong;

import java.awt.Rectangle;

import processing.core.PApplet;

public class PongBall extends MovableGameComponent {

	private int width = 10, height = 10;

	private Vector2 direction;
	private float speed; // pixel pro sekunde, siehe update

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}

	public Vector2 getDirection() {
		return direction;
	}

	public void setDirection(final Vector2 direction) {
		this.direction = direction;
	}

	public float getSpeed() {
		return speed;
	}

	public void setSpeed(float speed) {
		this.speed = speed;
	}

	public PongBall(final Vector2 position, final Vector2 velocity,
			final float speed) {
		super(position);
		this.direction = velocity;
		this.speed = speed;
		this.direction.normalize();
	}

	@Override
	public void draw(final PApplet applet) {
		applet.rect(this.position.getX(), this.position.getY(), width, height);
	}

	public void moveForTime(final float timeInMs) {
		this.position = this.position.add(direction.mult((timeInMs / 1000)
				* this.speed));
	}

	public boolean collidesWith(final Rectangle rect) {
		return rect.intersects(new Rectangle(
				(int) (this.position.getX() - width / 2), (int) (this.position
						.getY() - height / 2), width, height));
	}
}
